/**
 * 管理初始化
 */
var Wxuserinfo = {
    id: "WxuserinfoTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Wxuserinfo.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '昵称', field: 'nickname', visible: true, align: 'center', valign: 'middle'},
        {
            title: '性别', field: 'sex', formatter: function (value, row, index) {
                if (value == "1") {
                    return "男";
                } else if (value == "2") {
                    return "女";
                } else {
                    return "";
                }
            }, visible: true, align: 'center', valign: 'middle'
        },
        {title: '是否关注', field: 'subscribe',formatter: function (value, row, index) {
                if (value == "1") {
                    return "是";
                } else {
                    return "否";
                }
            }, visible: true, align: 'center', valign: 'middle'},
        {title: '所用语言', field: 'language', visible: true, align: 'center', valign: 'middle'},
        {title: '所在城市', field: 'city', visible: true, align: 'center', valign: 'middle'},
        {title: '所在省份', field: 'province', visible: true, align: 'center', valign: 'middle'},
        {title: '电话号码', field: 'phone', visible: true, align: 'center', valign: 'middle'},
        {title: '备注', field: 'remark', visible: true, align: 'center', valign: 'middle'},
        {title: '能否查看', field: 'isstaff',formatter: function (value, row, index) {
                if (value == "1") {
                    return "能";
                } else {
                    return "不能";
                }
            }, visible: true, align: 'center', valign: 'middle'},
        {title: '能否审核', field: 'isaudit',formatter: function (value, row, index) {
                if (value == "1") {
                    return "能";
                } else {
                    return "不能";
                }
            }, visible: true, align: 'center', valign: 'middle'},
        {title: '能否删除', field: 'isdelete',formatter: function (value, row, index) {
                if (value == "1") {
                    return "能";
                } else {
                    return "不能";
                }
            }, visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Wxuserinfo.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        Wxuserinfo.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
Wxuserinfo.openAddWxuserinfo = function () {
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/wxuserinfo/wxuserinfo_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看详情
 */
Wxuserinfo.openWxuserinfoDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '详情',
            area: ['800px', '660px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/wxuserinfo/wxuserinfo_update/' + Wxuserinfo.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
Wxuserinfo.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/wxuserinfo/delete", function (data) {
            Feng.success("删除成功!");
            Wxuserinfo.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("wxuserinfoId", this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询列表
 */
Wxuserinfo.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Wxuserinfo.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Wxuserinfo.initColumn();
    var table = new BSTable(Wxuserinfo.id, "/wxuserinfo/list", defaultColunms);
    table.setPaginationType("client");
    Wxuserinfo.table = table.init();
});
